package com.dw.etl.core.service;

import com.dw.etl.common.util.UUIDUtil;
import  com.dw.etl.common.vo.PaginationVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.EtlLogHandbatchService;
import com.dw.etl.core.mapper.EtlLogHandbatchMapper;
import com.dw.etl.core.bean.model.EtlLogHandbatch;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * etlLogHandbatch服务实现类
 * Created by hozeData on 2021/07/21.
 */
@Service
@Transactional
public class EtlLogHandbatchServiceImpl implements EtlLogHandbatchService{

    private static final Logger LOGGER = LoggerFactory.getLogger(EtlLogHandbatchServiceImpl.class);

    @Autowired
    private EtlLogHandbatchMapper etlLogHandbatchMapper;

    @Override
    public int insert(EtlLogHandbatch etlLogHandbatch) {
        if(StringUtils.isEmpty(etlLogHandbatch.getIdHandbatch())){
            String uuid32 = UUIDUtil.getUUID32();
            etlLogHandbatch.setIdHandbatch(uuid32);
        }
        return etlLogHandbatchMapper.insert(etlLogHandbatch);
    }

    @Override
    public int insertSelective(EtlLogHandbatch etlLogHandbatch)  {
        if(StringUtils.isEmpty(etlLogHandbatch.getIdHandbatch())){
            String uuid32 = UUIDUtil.getUUID32();
            etlLogHandbatch.setIdHandbatch(uuid32);
        }
        return etlLogHandbatchMapper.insertSelective(etlLogHandbatch);
    }

    @Override
    public int deleteById(String idHandbatch)  {
        return etlLogHandbatchMapper.deleteByPrimaryKey(idHandbatch);
    }

    @Override
    public int updateByIdSelective(EtlLogHandbatch etlLogHandbatch)  {

        return etlLogHandbatchMapper.updateByPrimaryKeySelective(etlLogHandbatch);
    }

    @Override
    public int updateById(EtlLogHandbatch etlLogHandbatch)  {
        return etlLogHandbatchMapper.updateByPrimaryKey(etlLogHandbatch);
    }

    @Override
    public EtlLogHandbatch getById(String idHandbatch)  {
        return etlLogHandbatchMapper.selectByPrimaryKey(idHandbatch);
    }

    @Override
    public List<EtlLogHandbatch> findByModel(EtlLogHandbatch etlLogHandbatch)  {
        return etlLogHandbatchMapper.findByModel(etlLogHandbatch);
    }

    @Override
    public PaginationVO<EtlLogHandbatch> findPageByModel(EtlLogHandbatch etlLogHandbatch, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<EtlLogHandbatch> quesList = etlLogHandbatchMapper.findByModel(etlLogHandbatch);
        PageInfo<EtlLogHandbatch> pageInfo = new PageInfo<>(quesList);
        PaginationVO<EtlLogHandbatch> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }





}
